<template>
<div class="grid h-lvh ">
    <fieldset class="fieldset bg-base-200 border-base-300 text-base-content rounded-box w-xs border p-4 mt-auto place-content-center place-self-center">
    <legend class="fieldset-legend">login</legend>

    <label class="label">用户名</label>
    <input type="text" class="input" placeholder="Username" v-model="username" />

    <label class="label">密码</label>
    <input type="password" class="input" placeholder="Password" v-model="password" />
    <button class="btn btn-neutral mt-4"  @click="onSubmit">登录</button>
    </fieldset>
</div>
</template>
<script setup>
import { useRouter } from 'vue-router';
import {useUserStore} from "@/store/userStore.js";
import {ref} from "vue";
import request from "@/js/axios.js";
import {useToast} from "vue-toastification";

let username=ref("admin")
let password=ref("admin111")
//路由跳转
const router = useRouter()
async function onSubmit(){
  const promise = await useUserStore().login(username.value, password.value)
  console.log(promise);
  if (promise) {
    useToast().success("登录成功")
    localStorage.setItem('token', 1)
    localStorage.setItem('username', username.value)
    await router.push('/index/home')
  } else {
    useToast().error("登录失败")
    localStorage.removeItem('token')
    localStorage.removeItem('username')
    await router.push('/')
  }
}
</script>
<style scoped>

</style>
